package com.hopu.v1.controller.front.exam;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.exam.ExamGrades;
import com.hopu.v1.service.front.exam.EGradesService;
import com.hopu.v1.utils.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: EGradesController
 * Description:
 *
 * @Author lh
 * @Create 2024/9/29 16:27
 * @Version 1.0
 */
@RestController
@RequestMapping("/grades")
public class EGradesController {
    @Autowired
    private EGradesService examGradesService;

    @GetMapping("/selectList")
    public R selectList(Page<ExamGrades> page, ExamGrades examGrades, String endTime) {
        System.out.println(examGrades);
        System.out.println(endTime);
        return R.ok(examGradesService.selectList(page, examGrades,endTime));
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @PostMapping("/batchDel")
    public R batchDel(ArrayList<Integer> ids) {
        System.out.println(ids);
        examGradesService.batchDel(ids);
        return R.ok("操作成功");
    }

    /**
     * 批量新增
     * @param examGradesList
     * @return
     */
    @PostMapping("/batchAdd")
    public R batchAdd(@RequestBody List<ExamGrades> examGradesList, HttpServletRequest request) {
        System.out.println(examGradesList);
        String token = request.getHeader("frontToken");
        String studentId = JwtUtils.getUserId(token);
        System.out.println(studentId);
        return R.ok("添加成功",examGradesService.batchAdd(studentId,examGradesList));
    }
}
